
#include "member_BAudioInput.h"
#include <BBuffer>

using namespace BWE;

member_BAudioInput::member_BAudioInput()
{
	recording = false;
#ifdef _WINDOWS_SYSTEM_
	wavform.wFormatTag = WAVE_FORMAT_PCM;  
	wavform.nChannels = 2;
	wavform.nSamplesPerSec = 44100;
	wavform.nAvgBytesPerSec = 44100*16*2/8;
	wavform.nBlockAlign = 4;
	wavform.wBitsPerSample = 16;
	wavform.cbSize = 0;

	for(int i = 0; i < BUFFER_NUM; i++)
	{
		wavhdr[i].lpData = new char[BUFFER_SIZE];
		wavhdr[i].dwBufferLength = BUFFER_SIZE;
		wavhdr[i].dwBytesRecorded = 0;
		wavhdr[i].dwUser = NULL;
		wavhdr[i].dwFlags = 0;
		wavhdr[i].dwLoops = 1;
		wavhdr[i].lpNext = NULL;
		wavhdr[i].reserved = 0;
	}
#endif
}
member_BAudioInput::~member_BAudioInput()
{

}

bool member_BAudioInput::callback(BAudioInput* audio, const char* buffer, int size)
{
	BBuffer* buf = new BBuffer(size);
	buf->write(buffer, size);
	BAudioEvent audioEvent(Event_Input);
	audioEvent.setBuffer(buf);
	return audio->audioEvent(audioEvent);
}

bool member_BAudioInput::log(const BString& text)
{
	logText << text << '\n';
	return true;
}
